import { AxiosInstance, AxiosStatic ,AxiosRequestConfig } from './types/index';
import defaults from './default';
import Axios from './core/Axios'
import { extend } from './helpers/util'
import mergeConfig from './core/meregeConfig';

function createInstance(initConfig: AxiosRequestConfig): AxiosStatic {
  const context = new Axios(initConfig);
  const instance = Axios.prototype.request.bind(context)
  extend(instance, context)
  return  instance as AxiosStatic
}

const axios = createInstance(defaults);

axios.create = function(config) {
  return createInstance(mergeConfig(defaults, config))
}

export default axios